package com.jsgt.greekfire.ui.trading.billcoin.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.fhx.core.base.BaseAdapter
import com.fhx.core.base.BaseViewHolder
import com.fhx.core.utils.DateFormatUtil
import com.jsgt.greekfire.R
import com.jsgt.greekfire.bean.BillBean

/**
 * author fhx
 * create time 2020/4/24 10:09
 **/
class BillAdapter : BaseAdapter<BillBean>() {

    inner class VH(itemView: View) : BaseViewHolder(itemView) {
        var bill_content_tv: TextView? = null
        var bill_time_tv: TextView? = null
        var bill_sum_tv: TextView? = null
        var bill_amt_tv: TextView? = null
        var bill_balance_tv: TextView? = null

        init {
            bill_content_tv = itemView.findViewById(R.id.bill_content_tv)
            bill_time_tv = itemView.findViewById(R.id.bill_time_tv)
            bill_sum_tv = itemView.findViewById(R.id.bill_sum_tv)
            bill_amt_tv = itemView.findViewById(R.id.bill_amt_tv)
            bill_balance_tv = itemView.findViewById(R.id.bill_balance_tv)
        }

        fun bindData(billBean: BillBean) {
            when (billBean.assetEvent) {
                1 -> bill_content_tv?.text = "USDT\t充币"
                2 -> bill_content_tv?.text = "USDT\t提现"
                3 -> bill_content_tv?.text = "USDT\t买入"
                4 -> bill_content_tv?.text = "USDT\t卖出"
                11 -> bill_content_tv?.text = "USDT\t抢购"
            }
            bill_time_tv?.text = DateFormatUtil.formatNew(billBean.createTime, "MM月dd日 HH:mm")
            if (billBean.assetAmt!! > 0) {
                bill_sum_tv?.setTextColor(itemView.resources.getColor(R.color.red_DE6C65))
                bill_sum_tv?.text = "+${billBean.assetAmt}"
            } else {
                bill_sum_tv?.setTextColor(itemView.resources.getColor(R.color.green_6AB578))
                bill_sum_tv?.text = billBean.assetAmt.toString()
            }
            bill_amt_tv?.text = "手续费 0.1"
            bill_balance_tv?.text = "余额\t${billBean.assetAfter}"
        }
    }

    override fun provideViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder? {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_bill, parent, false)
        return VH(view)
    }
    override fun onBindViewHolder(holder: BaseViewHolder, position: Int) {
        val viewHolder = holder as VH
        viewHolder.bindData(dataList()[position])
    }
}